//用户注册功能
//1.收集并检验数据
//2.提交数据
document.querySelector('#btn-login').addEventListener('click',()=>{
    const form =document.querySelector('.login-form')
    const data =serialize(form,{empty:true,hash:true})
    const  { username,password}=data
    //非空判断
    if(username ==='' || password ===''){
       showToast('用户名或密码不能为空')
       return
    }
    //长度校验
    if(username.length< 8||username.length>15 || password.length<6 ||password.length>15){
       showToast('用户名长度8-15,密码长度6-15')
       return
    }
    try{
        const res= await axios.post('/login',{username,password})
        showToast(res.data.message)
        //3.缓存数据
        localStorage.setItem('token',re.data.data.token)
        localStorage.setItem('username',re.data.data.username)
        setTimeout(()=>{
            loaction.href='./index.html'
        },1000)
     }catch(error){
        showToast(error.response.data.message)
     }
})